package com.coocaa.ops.common.tool.algorithm;

import lombok.experimental.UtilityClass;
import org.springframework.util.Assert;

import java.util.zip.CRC32;

/**
 * @author bjh
 * @description
 * @date 2021/2/2 09:23
 */
@UtilityClass
public class CrcUtil {

    public static long getCrc32(String url){
        Assert.hasText(url, "图片地址不能为空");
        CRC32 crc32 = new CRC32();
        //Resets CRC-32 to initial value.
        crc32.reset();
        //将数据丢入CRC32解码器
        byte[] bytes = url.getBytes();
        crc32.update(bytes);
        //获取CRC32 的值  默认返回值类型为long 用于保证返回值是一个正数
        long value = crc32.getValue();
        return value;
    }

    public static void main(String[] args) {
        String url = "http://172.20.154.101/img/tvos6_imgs_beta/20210202/20210202102733059033_320*300.jpg";
        long res = getCrc32(url);
        System.out.println(res);
    }
}
